package com.yc.system.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.system.entity.Book;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import  com.yc.system.service.IBookCartLikeService;


import com.yc.framework.baseClass.BaseController;
//import com.yc.framework.baseClass.ServiceFacade;
import com.yc.framework.baseClass.R;
import com.yc.system.entity.BookCartLike;
/**
 * <p>
    * 购物车/收藏 前端控制器
    * </p>
 *
 * @author 1850140986@qq.com
 * @since 2022-12-03
 */
@RestController
public class BookCartLikeController extends BaseController
    {

    @Autowired
  private IBookCartLikeService service;

  /**
   * 根据条件分页查询BookCartLike
   * @param model 实体对象
   * @return 查询列表
   */
     @PostMapping("/sys/bookCartLike/list")
    public R list(@RequestBody BookCartLike model){
        return service.list(model);

    }

    /**
    * 根据主键查询单个对象
    * @param model 实体对象包含uuid
    * @return 成功或失败
    */
    @GetMapping("/sys/bookCartLike/getById/{id}")
    public R getById(@PathVariable String id) {
        return service.getModelById(id);
    }

    /**
	 * 新增实体对象
	 *
     * @param model 实体对象
	 * @return 新增是否成功
	 */
     @PostMapping("/sys/bookCartLike/saveCart")
	public R saveCart(@RequestBody BookCartLike model) {
		return service.saveCart(model);

	}

    /**
	 * 批量新增实体对象
	 *
     * @param modelList 实体对象列表
	 * @return 新增是否成功
	 */
	@PostMapping("/sys/bookCartLike/saveBatch")
	public R saveBatch(@RequestBody List<BookCartLike> modelList) {
		return service.saveModelBatch(modelList);

	}

    /**
	 * 根据主键删除实体
	 *
     * @param uuid 实体携带主键
	 * @return 删除是否成功
	 */
	@DeleteMapping("/sys/bookCartLike/removeById/{id}")
	public R removeById(@PathVariable String id) {
		return service.removeModelById(id);
	}

     /**
	 * 根据主键列表删除实体
	 *
     * @param idList 实体主键
	 * @return 删除是否成功

	@DeleteMapping("/removeByIdList")
	public R removeByIdList(@RequestBody List<BookCartLike> idList) {
        return service.removeModelByIdList(idList);

    }
 */
    /**
    * 根据主键修改实体
    *
    * @param model 等待修改的对象
    * @return 修改是否成功
    */
    @PutMapping("/sys/bookCartLike/updateById")
    public R updateModelById(@RequestBody BookCartLike model) {
        return service.updateModelById(model);

    }

    /**
    * 根据主键列表修改实体列表
    *
    * @param modelList 等待修改的对象列表
    * @return 修改是否成功
    */
    @PostMapping("/sys/bookCartLike/updateByIdBatch")
    public R updateModelByIdBatch(@RequestBody List<BookCartLike> modelList) {
        return service.updateModelByIdBatch(modelList);

    }

      /**
	 * 根据多主键列表删除实体
	 *
     * @param idList 多主键
	 * @return 删除是否成功
	 */
	@DeleteMapping("/sys/bookCartLike/removeByIds/{ids}")
	public R removeByIdList(@PathVariable String ids) {
        return service.removeModelByIds(ids);

    }

    @GetMapping("/sys/bookCartLike/getBCLByUserId")
		public R getBCLByUserId(@RequestParam("userId") int userId,@RequestParam("bookId") int bookId){
		return service.getBCLByUserId(userId,bookId);
	}

		@PostMapping("/sys/bookCartLike/updateByclId")
		public R updateByclId(@RequestBody BookCartLike model) {
			return service.updateByclId(model);
		}

		@PostMapping("sys/cart/getByPage")
		public R getCartByPage(@RequestBody Book findByPage){
			IPage<Book> page = new Page<>(findByPage.getPageNum() ,findByPage.getPageSize());
			QueryWrapper<Book> wrapper = new QueryWrapper<>();
//			wrapper.like("product_name","v");
			return service.getCartByPage(page, wrapper, 1,findByPage.getUserId());
		}
		@PostMapping("sys/cart/delete")
		public R delete(@RequestBody BookCartLike bookCartLike){
			return service.deleteCartById(bookCartLike.getClId());
		}

		@PostMapping("sys/bookCartLike/saveLike")
		public R saveLike(@RequestBody BookCartLike bookCartLike){
			return service.saveLike(bookCartLike);
		}

		@PostMapping("sys/bookCartLike/deleteLike")
		public R deleteLike(@RequestBody BookCartLike bookCartLike){
			return service.deleteLike(bookCartLike);
		}


		@PostMapping("sys/bookOrder/addCartNum")
		public R addCartNum(@RequestBody BookCartLike bookCartLike){
			return service.changeNum(bookCartLike,1);
		}

		@PostMapping("sys/bookOrder/reduceCartNum")
		public R reduceCartNum(@RequestBody BookCartLike bookCartLike){
			return service.changeNum(bookCartLike,0);
		}




}
